<template>
    <div>
    <div v-show="ad==1">
        <el-form :model="AdmExpressag" label-width="90px">
            <el-container>
                <el-form-item label="发件人：">
                    <el-input v-model="AdmExpressag.systemUserAddresser"  size="small" placeholder="用户名" style="width: 100px"></el-input>
                </el-form-item>
                <el-form-item label="快递公司:">
                    <el-select v-model="AdmExpressag.expressageSendWaayId" placeholder="请选择" size="small" style="width: 100px">
                        <el-option label="--请选择--" value=""></el-option>
                        <el-option v-for="ite in SendWaayS" :key="ite.id" :label="ite.sendName" :value="ite.id"></el-option> </el-select>
                </el-form-item>
                <el-form-item label="快件类型:" >
                    <el-select v-model="AdmExpressag.expssagereExpressTypeId" placeholder="请选择" size="small"  style="width: 100px">
                        <el-option label="--请选择--" value=""></el-option>
                        <el-option v-for="item in Exps" :key="item.id" :label="item.expressName" :value="item.id" ></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="GetAdmExpressag" size="small" >查询</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button @click="AddExpssa" size="small" >添加收件</el-button>
                </el-form-item>
            </el-container>
        </el-form>
        <el-table :data="AdmExpressags.slice((currentPage-1)*pagesize,currentPage*pagesize)" height="500" border style="width: 100%">
            <el-table-column label="发件人" prop="systemUserAddresser"></el-table-column>
            <el-table-column label="发件日期" prop="expressageSendadate"></el-table-column>
            <el-table-column label="案号" prop="caseNo"> </el-table-column>
            <el-table-column label="发件公司" prop="sname"> </el-table-column>
            <el-table-column label="发件类型" prop="ename"></el-table-column>
            <el-table-column label="快递费" prop="expressFee"></el-table-column>
            <el-table-column label="收件人" prop="collarPerson"></el-table-column>
            <el-table-column label="订单号" prop="expressageCourierNumber"></el-table-column>
            <el-table-column label="收件单位" prop="expressageSendaunit"></el-table-column>
            <el-table-column label="备注说明" prop="expressageRemark"></el-table-column>
            <el-table-column label="操作">
                <template slot-scope="scope">
                    <el-dropdown>
                        <el-button type="primary">
                            操作<i class="el-icon-arrow-down el-icon--right"></i>
                        </el-button>
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item @click.native="GetAdmExpressagById(scope)">详情</el-dropdown-item>
                            <el-dropdown-item @click.native="GetAdmEByidupdate(scope)">修改</el-dropdown-item>
                            <el-dropdown-item @click.native="DelExpressagById(scope)">删除</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[5, 10, 20, 40]"
                :page-size="pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="AdmExpressags.length">
        </el-pagination>
    </div>
        <adm-expall :ada="ad" :tue="tue" :AdmExpr="AdmExp" @AddAdmExpre="addAdmExpre" @coles="coles" v-if="ad==2"></adm-expall>
    </div>
</template>

<script>
    import AdmExpall from "../AdmExpressage/AdmExpressagAllF"
    import admexp from "../../../model/gsl/AdmExpressage/admexpressage";
    const adme=admexp.getInstance();
    import sendwaay from "../../../model/gsl/SendWaay/sendwaay";
    const send=sendwaay.getInstance();
    import express from "../../../model/gsl/ExpressType/expresstype";
    const exp=express.getInstance();
    export default{
        components:{AdmExpall},
        data() {
            return {
                ad:1,
                currentPage:1, //初始页
                pagesize:10,    //    每页的数
                AdmExpressags:[],
                AdmExpressag:{},//高级查询的数据
                SendWaayS:[],//快递公司的数据
                Exps:[],//快件类型的数据
                AdmExp:{},//根据id查询的数据
                tue:false,//控制输入框是否可以修改 默认不能修改
            };
        },
        created(){
            this.GetAdmExpressag();
            this.GetSendWaays();
            this.GetExpressType();
        },
        methods: {
            // 初始页currentPage、初始每页数据数pagesize和数据data
            handleSizeChange: function (size) {
                this.pagesize = size;
                console.log(this.pagesize)  //每页下拉显示数据
            },
            handleCurrentChange: function(currentPage){
                this.currentPage = currentPage;
                console.log(this.currentPage)  //点击第几页
            },
            GetAdmExpressag(){
               this.AdmExpressag.expressageType='F'
                adme.list(this.AdmExpressag).then((re)=>{
                    this.AdmExpressags=re.data.data;
                    this.AdmExpressag={}
                })
            }, GetSendWaays(){
                send.list(null).then((re)=>{
                    this.SendWaayS=re.data.data;
                })
            },
            GetExpressType(){
                exp.list(null).then((re)=>{
                    this.Exps=re.data.data;
                })
            },
            coles(){
                this.ad=1
            },
            AddExpssa(){
                this.AdmExp={}
                this.ad=2;
                this.tue=false;
            },
            GetAdmExpressagById(s){
                this.AdmExp={}
                adme.listByid(s.row.id).then((re)=>{
                    this.AdmExp=re.data.data;
                    this.ad=2;
                    this.tue=true;
                })
            },GetAdmEByidupdate(s){
                this.AdmExp={}
                adme.listByid(s.row.id).then((re)=>{
                    this.AdmExp=re.data.data;
                    this.ad=2;
                    this.tue=false;
                })
            },
            DelExpressagById(s){
                adme.rows(s.row.id).then((re)=>{
                    if (re.data.data==1) {
                        this.$message.success({
                            message:'删除成功',
                            duration:1000
                        })
                        this.GetAdmExpressag();
                        this.ad=1;
                    }else {
                        alert("删除失败！")
                        this.ad=2;
                    }
                })
            },
            addAdmExpre(exps){
                console.log(exps);
                exps.expressageType='F'
                if (exps.id) {
                    adme.update(exps).then((re)=>{
                        if (re.data.data==1) {
                            this.$message.success({
                                message:'修改成功',
                                duration:1000
                            })
                            this.GetAdmExpressag();
                            this.ad=1;
                        }else {
                            alert("修改失败！")
                            this.ad=2;
                        }
                    })
                }else {
                    adme.save(exps).then((re)=>{
                        if (re.data.data==1) {
                            this.$message.success({
                                message:'添加成功',
                                duration:2000
                            })
                            this.GetAdmExpressag();
                            this.ad=1;
                        }else {
                            alert("添加失败！")
                            this.ad=2;
                        }
                    })
                }
            }
        }
    }
</script>
